package com.deepgames.mud.action.data;

import com.deepgames.mud.action.ActionLibrary;
import com.deepgames.mud.core.InternalCode;
import com.deepgames.mud.gobject.GobjectExtractor;
import com.deepgames.mud.session.SessionManager;

/**
 * Grants actions access to certain essential external API methods, allowing
 * 	Actions to interface with sessions, extract Gobjects, and invoke other
 * 	Actions.
 * 
 * @author Zack Hoffmann
 * @version 0.1
 *
 */
public class ActionContext {
	
	private SessionManager sessions;
	private GobjectExtractor gobjects;
	private ActionLibrary library;
	
	/**
	 * Builds a new ActionContext based on current game instances of
	 * 	fundamental classes.
	 * 
	 * @param sessions		Current game instance of SessionManager.
	 * @param gobjects		Current game instance of GobjectExtractor.
	 * @param actions		Current game instance of ActionLibrary.
	 */
	public ActionContext(SessionManager sessions, GobjectExtractor gobjects,
			ActionLibrary library) {
		this.sessions = sessions;
		this.gobjects = gobjects;
		this.library = library;
	}
	
	/**
	 * Provides the game instance of the GobjectExtractor.
	 * @see GobjectExtractor
	 * 
	 * @return				The current GobjectExtractor instance.
	 */
	public GobjectExtractor getGobjectExtractor() {
		return this.gobjects;
	}
	
	/**
	 * Provides access to SessionManager.sendMsgToPlayer(String,String).
	 * @see SessionManager
	 * 
	 * @param playerID		The unique identifier of the player to send the
	 * 						message to.
	 * @param msg			The text message to send.
	 * @return				Status code.  {@link InternalCode}
	 */
	public int sendMsg(String playerID, String msg) {
		int status = InternalCode.FAILURE;
		status = sessions.sendMsgToPlayer(playerID, msg);
		return status;
	}
	
	/**
	 * Provides access to the action library for nested Action calls.
	 * 
	 * @param command		The name of the action to retrieve.
	 * @return				The action referenced by the command text.
	 */
	public Action lookupAction(String command) {
		return library.lookupAction(command);
	}
}